﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CUREDataAccessLayers;
using CUREEntity;
using System.Data;

/*************************************************************************************

     * 作   者： 张 颖
  
*************************************************************************************/
namespace CUREBusinessLogicLayer
{
    public class MasterBll
    {
        MasterDal masterdal = new MasterDal();

        /// <summary>
        /// 获取用户数据信息
        /// </summary>
        /// <returns></returns>
        public DataSet GetMasterData(IDictionary<string, object> where, int pageIndex, int pageSize, out int totalRecordCount, out int totalPageCount)
        {
            DataSet ds = new DataSet();
            try
            {
                ds = masterdal.GetMasterData(where, pageIndex, pageSize, out totalRecordCount, out totalPageCount);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return ds;
        }
        /// <summary>
        /// 获取用户数据信息
        /// </summary>
        /// <returns></returns>
        public DataTable  GetUserInfoById(string ID)
        {
           DataTable dt = new DataTable ();
            try
            {
                dt = masterdal.GetUserInfoById(ID);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return dt;
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="id"></param>
        /// <param name="num"></param>
        /// <param name="type"></param>
        /// <param name="persson"></param>
        /// <param name="time"></param>
        /// <returns>返回true或false true 添加成功；false 添加失败</returns>
        public bool InsertMasterData(IDictionary<string, object> where)
        {
            bool result = false;
            try
            {
                result = masterdal.InsertMasterData(where);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return result;
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="num"></param>
        /// <param name="type"></param>
        /// <param name="persson"></param>
        /// <param name="time"></param>
        /// <returns>返回true或false true 更新成功；false 更新失败</returns>
        public bool UpdateMaterData(IDictionary<string, object> where)
        {
            bool result = false;
            try
            {
                result = masterdal.UpdateMasterData(where);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns>返回true或false true删除成功；false 删除失败</returns>
        public bool DeleteMasterData(string delid)
        {
            bool result = false;
            try
            {
                result = masterdal.DeleteMasterData(delid);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>返回true或false true 更新成功；false 更新失败</returns>
        public bool RestoreMaterData(string resid)
        {
            bool result = false;
            try
            {
                result = masterdal.RestoreMasterData(resid);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        /// <summary>
        /// 根据id获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns>返回表</returns>
        public DataTable GetMaster(string id)
        {
            DataTable dt = new DataTable();
            DataTable table = masterdal.GetMasterById(id);
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }

        /// <summary>
        /// 获取用户id，name
        /// </summary>
        /// <returns>返回表</returns>
        public DataTable GetUser(string userName)
        {
            DataTable dt = new DataTable();
            DataTable table = masterdal.GetMaster(userName);
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }

        /// <summary>
        /// 根据用户名称获取用户ID
        /// </summary>
        /// <param name="userName">用户名称</param>
        /// <returns>用户ID</returns>
        /// zcf  2014年10月27日13
        public decimal GetMasterIDbyName(string userName)
        {
            return masterdal.GetMasterIDbyName(userName);
        }

        /// <summary>
        /// 获取角色
        /// </summary>
        /// <returns></returns>
        public DataTable GetGroup()
        {
            DataTable dt = new DataTable();
            DataTable table = masterdal.GetGroup();
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }

        /// <summary>
        /// 获取部门
        /// </summary>
        /// <returns></returns>
        public DataTable GetDept()
        {
            DataTable dt = new DataTable();
            DataTable table = masterdal.GetDept();
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }

        /// <summary>
        /// 获取职能
        /// </summary>
        /// <returns></returns>
        public DataTable GetJob()
        {
            DataTable dt = new DataTable();
            DataTable table = masterdal.GetJob();
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }

        /// <summary>
        /// 获取等级
        /// </summary>
        /// <returns></returns>
        public DataTable GetSkilllevel()
        {
            DataTable dt = new DataTable();
            DataTable table = masterdal.GetSkilllevel();
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }

        /// <summary>
        /// 判断员工编号是否存在
        /// </summary>
        /// <returns></returns>
        public bool SelectEmployees(string id)
        {
            bool isExist = masterdal.JudgeMasterIDExist(id);
            return isExist;
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="where">userid:用户编号，password:新密码</param>
        /// <returns></returns>
        public bool UpdateMasterPassword(IDictionary<string, object> where)
        {
            bool result = false;
            try
            {
                result = masterdal.UpdateMasterPassword(where);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return result;
        }

        /// <summary>
        /// 判断原始密码是否正确
        /// </summary>
        /// <param name="where">userid:用户编号，oldpassword:原始密码</param>
        /// <returns>true：正确，false：错误</returns>
        public bool CheckMasterPassword(IDictionary<string, object> where)
        {
            bool result = false;
            try
            {
                result = masterdal.CheckMasterPassword(where);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return result;
        }

        /// <summary>
        /// 打印员工编号
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public DataTable GetprintUserNum(IDictionary<string, object> where)
        {
            return masterdal.SelectprintUserNum(where);
        }
    }
}
